package cn.ciis.basic.event;

import cn.ciis.basic.base.BaseCache;
import cn.ciis.basic.kit.J2CacheKit;
import cn.ciis.basic.websocket.AuthorityWebSocket;
import cn.hutool.core.date.DateUtil;
import com.jfinal.aop.Aop;
import com.jfinal.kit.LogKit;
import com.jfinal.kit.Ret;
import net.dreamlu.event.core.EventListener;
import net.oschina.j2cache.CacheObject;

import java.util.Date;

public class OpenDebugEventListen {

    AuthorityWebSocket authorityWebSocket= Aop.get(AuthorityWebSocket.class);

    @EventListener(async = true)
    public void OpenDebugEventListen(OpenDebugEvent event){

        String str = event.getCiisPacket().getDec();

        LogKit.info("客户端指令：{}",str);

        CacheObject cacheObject = J2CacheKit.get(BaseCache.WS_SESSION_ID_DICTIONARY, event.getBsId() + "debug",false);

        if(null != cacheObject && null != cacheObject.getValue()){
            authorityWebSocket.sendMsg(cacheObject.getValue().toString(), Ret.ok("msg",str)
                    .set("date", DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"))
                    .set("isDownload",event.isDownload()).set("category","debug").toJson());
        }
    }
}
